package com.module.content.ui.info

import android.app.Application
import androidx.lifecycle.LiveData
import com.allen.app.data.bean.Info
import com.allen.app.data.bean.InfoBean
import com.allen.app.data.network.API
import com.allen.app.data.repository.InfoRepository
import com.allen.base.base.basic.model.ListViewModel
import com.module.content.utils.InfoIndex

/**
 * author : Allen
 * date   : 2020/08/13
 * time   : 17:07
 * desc   :
 */
class InfoViewModel(application: Application) : ListViewModel<Info, InfoBean>(application) {
    override fun loadData(vararg params: Int): LiveData<Info> = emit {
        val api = InfoRepository.getInstance(API.getInstance())
        val page = params[0]
        if (params.size >= 2) {
            when (params[1]) {
                InfoIndex.INFO_ATTENTION -> api.getArticleFollowList(page)
                InfoIndex.INFO_IMAGE -> api.getArticleList("imgrank", page)
                InfoIndex.INFO_VIDEO -> api.getArticleList("video", page)
                InfoIndex.INFO_TEXT -> api.getArticleList("text", page)
                InfoIndex.INFO_ESSENCE -> api.getArticleList("day", page)
                InfoIndex.INFO_NEWSPAPER -> api.getTopicArticleList(page)
                else -> api.getNewList(page)
            }
        } else {
            api.getNewList(page)
        }
    }

}